from django import template
from django.template import Context, Template

from util import parse_args_kwargs_and_as_var

register = template.Library()

@register.tag(name="list")
def do_list(parser, token):
    nodelist = parser.parse(('endlist',))
    args, kwargs, as_var = parse_args_kwargs_and_as_var(parser, token.split_contents()[1:])
    parser.delete_first_token()
    return ListNode(args, kwargs, as_var, nodelist)

class ListNode(template.Node):
    def __init__(self, args, kwargs, as_var, nodelist):
        self.nodelist = nodelist

	#data_to_bind
        if ("data_to_bind" in kwargs):
            self.bind_mode = "data"
            self.data = template.Variable(kwargs["data_to_bind"])
        else:
            self.bind_mode = "query"
            self.data = kwargs["query_to_bind"]

	#stylesheet


        #scroll_var


	#js_events_var


	
    def render(self, context):
        output = ""
        for d in iter(self.data.resolve(context)):
            output += self.nodelist.render(Context(d))
        return output
